<template>
  <div id='my-preview'>

    <form-preview @click.native='goLink()' v-if='show' :header-label="list.raceMessage.name" :header-value="list.bib?'参赛号:'+list.bib:'参赛号未分配'" :body-items="bodyItem">
    </form-preview>

  </div>

</template>
<script type="text/ecmascript-6">
import { axios } from "@/api/axios.js";
import { FormPreview } from "vux";
import { cityData } from "@/common/locales/cityData.js";
import { countryData } from "@/common/locales/countryData1.js";
import {
  isIdNumber,
  setTitle,
  formatCity,
  hostoperating
} from "@/common/js/main.js";

/* eslint-disable*/
export default {
  props: {
    list: {
      type: Object
    },
    name: {
      type: String
    }
  },
  data() {
    return {
      bodyItem: [],
      eventInfo: {},
      show: false
    };
  },
  created() {
    //console.log(this.list)
    //console.log(this.list);
    //console.log("---");
    //console.log(this.list);
    //console.warn(this.list.eventid);

    this.getEventinfo(this.list.eventid);
  },
  methods: {
    goLink() {
      //console.log(this.list.raceMessage.id)
      this.$router.push({
        path: `/message?race_id=${this.list.raceMessage.id}`
      });
    },
    getEventinfo(eventid) {
      //console.log("---");
      let _this = this;
      axios
        .get(`${window.host}event/show`, {
          params: {
            eventid: eventid
          }
        })
        .then(function(response) {
          //this.eventInfo = response.data;
          //console.log(response.data);
          //console.log("---");
          //console.warn(response.data.data);
          //console.warn(_this.list);

          _this.bodyItem.push({ label: "姓名", value: _this.list.name });

          _this.bodyItem.push({
            label: "项目",
            value: response.data.data.name
          });

          _this.bodyItem.push({
            label: "参赛号",
            value: _this.list.bib ? _this.list.bib : "参赛号未分配"
          });
          _this.bodyItem.push({
            label: "比赛日期",
            value:
              _this.list.raceMessage.time.split(" ")[0] +
              " " +
              _this.list.raceMessage.time.split(" ")[1].split(":")[0] +
              ":" +
              _this.list.raceMessage.time.split(" ")[1].split(":")[1]
          });

          var address_name = "";
          //onsole.warn('----')
          //console.log(_this.list.raceMessage)
          if (!!_this.list.raceMessage.city) {
            address_name = formatCity(_this.list.raceMessage.city + ",");
            //console.log('city')
            //console.log(address_name)
          }

          _this.bodyItem.push({
            label: "比赛地点",
            value: address_name + _this.list.raceMessage.address
          });
          if (!!_this.lists && !!_this.lists.invite) {
            var message = "报名成功/邀请码报名";
            this.stateMessage = message;
          } else if (!!_this.list.refundid) {
            //有退款
            var message = "有退款";
            _this.bodyItem.push({ label: "报名状态", value: `${message}` });
          } else if (!!_this.list.pay_at) {
            //未支付
            var message = "/已支付";
          } else {
            var message = "/未支付";
          }
          //添加状态
          if (_this.list.state === "normal" && !!_this.list.pay_at) {
            _this.bodyItem.push({
              label: "报名状态",
              value: "报名成功" + message
            });
          } else if (_this.list.state === "normal") {
            _this.bodyItem.push({
              label: "报名状态",
              value: "报名正常" + message
            });
          } else if (_this.list.state === "waitfail") {
            //候补失败
            _this.bodyItem.push({
              label: "报名状态",
              value: `候补结束，未获得名额`
            });
          } else if (_this.list.state === "wait") {
            if (!!_this.list.pos) {
              //候补 有post人数
              _this.bodyItem.push({
                label: "报名状态",
                value:
                  _this.$t("message.alternate") +
                  "(前边有" +
                  _this.lists.pos +
                  "人)" +
                  message
              });
            } else {
              //候补 没有post人数
              _this.bodyItem.push({
                label: "报名状态",
                value: _this.$t("message.alternate") + message
              });
            }
          } else if (_this.list.state == "draw") {
            _this.bodyItem.push({
              label: "报名状态",
              value: `等待抽签` + message
            });
          } else if (_this.list.state === "undraw") {
            _this.bodyItem.push({
              label: "报名状态",
              value: `未中签(候补代码${_this.lists.wait_pos})` + message
            });
          } else if (_this.list.state === "audit") {
            _this.bodyItem.push({
              label: "报名状态",
              value: `审核中` + message
            });
          } else if (_this.list.state === "auditfail") {
            _this.bodyItem.push({
              label: "报名状态",
              value: `未通过审核(${_this.lists.refusemsg})` + message
            });
          }

          if (!!_this.list.data) {
            switch (_this.list.data.state) {
              case "FINISH":
                _this.bodyItem.push({
                  label: "完赛状态",
                  value: "完赛"
                });
                break;
              case "DNF":
                _this.bodyItem.push({
                  label: "完赛状态",
                  value: "未完赛"
                });
                break;
              case "DNS":
                _this.bodyItem.push({
                  label: "完赛状态",
                  value: "未出发"
                });
                break;
              case "DSQ":
                _this.bodyItem.push({
                  label: "完赛状态",
                  value: "取消成绩"
                });
                break;
              default:
            }
          } else {
            // _this.bodyItem.push({
            //   label: "完赛状态",
            //   value: "未完赛"
            // });
          }

          _this.show = true;
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  },
  components: {
    FormPreview
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" rel="stylesheet/less">
#my-preview {
  margin-top: 1.17647059em;
}
</style>
